package com.heima.util;


import org.springframework.stereotype.Component;

import java.security.SecureRandom;
import java.util.Random;
@Component
    public class RandomUtil {
        private static final String SYMBOLS = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; // 数字,26个小写字母和26个大写字母组成
        private static final Random RANDOM = new SecureRandom();
    private static final String SMALL = "0123456789abcdefghijklmnopqrstuvwxyz"; // 数字和26个小写字母组成
        /**
         * 获取长度为 8 的随机字母+数字
         *
         * @return 随机数字
         */
        public String getRandomNumber() {
            char[] nonceChars = new char[8];  //指定长度为8位/自己可以要求设置

            for (int index = 0; index < nonceChars.length; ++index) {
                nonceChars[index] = SYMBOLS.charAt(RANDOM.nextInt(SYMBOLS.length()));
            }
            return new String(nonceChars);
        }
        public String getSmallRandomNumber(){
            char[] nonceChars = new char[8];  //指定长度为8位/自己可以要求设置

            for (int index = 0; index < nonceChars.length; ++index) {
                nonceChars[index] = SMALL.charAt(RANDOM.nextInt(SMALL.length()));
            }
            return new String(nonceChars);
        }
    }
